package main

import (
	"fmt"
	"time"
)


func NewTimer(sec time.Duration, f func()){
	ticker := time.NewTicker(sec*time.Second) //定义一个1秒间隔的定时器
	go func() {
		for { //循环
			<-ticker.C
			f()
			ticker.Stop() //停止定时器
		}
	}()
}

func test()  {
	fmt.Println("i am test")
}
func test2()  {
	fmt.Println("i am test2")
}

func main()  {
	fmt.Println("time ticker")

	NewTimer(1, test)
	NewTimer(2, test2)
	time.Sleep(10 * time.Second)
}